<?php

namespace addons\shopro\console;

use addons\shopro\service\commission\Agent as AgentService;
use think\console\Input;
use think\console\Output;
use think\Db;
use think\exception\HttpResponseException;

class ShoproLevel5Share extends Command
{

    protected $input = null;
    protected $output = null;

    /**
     * 帮助命令配置
     */
    protected function configure()
    {
        $this->setName('shopro:level5share')
            ->setDescription('金牌会员分红');
    }


    /**
     * 执行帮助命令
     */
    protected function execute(Input $input, Output $output)
    {
//        \think\Queue::push('\addons\shopro\job\Commission@runAgentLevel5SharMoney', [], 'shopro');
        try {
            $userId = 1;
            $agent = new AgentService($userId);

            if ($agent->user) {
                Db::transaction(function () use ($agent) {
                    $agent->runAgentLevel5SharMoney();
                });
            }
        } catch (HttpResponseException $e) {
            $data = $e->getResponse()->getData();
            $message = $data ? ($data['msg'] ?? '') : $e->getMessage();
            format_log_error($e, 'runMonthSharMoney.HttpResponseException', $message);
        } catch (\Exception $e) {
            format_log_error($e, 'runMonthSharMoney');
        }
    }

}
